package com.wu.controller;/**
 * @author sun
 * @date 2022/3/27 - 22:42
 */

import com.wu.pojo.Labels;
import com.wu.service.LabelsService;
import com.wu.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: TODO
 * @author 孙
 * @date 2022/3/27 22:42
 * @version 1.0
 */
@RestController
@Api(tags="Labels模块")
@CrossOrigin
@RequestMapping("labels")
public class LabelsController {
    @Autowired
    private LabelsService labelsService;
    @PostMapping("/insertLabels")
    @ApiOperation(value="增加Labels")
    public R insertLabels(@RequestBody Labels labels){
        try {
            labelsService.insertSelective(labels);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }

    }


    @GetMapping("/deleteLabels/{id}")
    @ApiOperation(value="删除Labels")
    public R deleteLabels(Integer id){
        try {
            labelsService.deleteByPrimaryKey(id);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @PutMapping("/updateLabels")
    @ApiOperation(value="更新Labels")
    public R updateLabels(@RequestBody Labels labels){
        try {
            labelsService.updateByPrimaryKeySelective(labels);
            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findLabels")
    @ApiOperation(value="查询LabelsList")
    public R findLabels(Labels labels){
        try {
            List<Labels> list= labelsService.findLabels(labels);
            return R.ok().data("labelsList",list);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/findLabelsById/{id}")
    @ApiOperation(value="通过id查询Labels")
    public R findLabels(Integer id){
        try {
            Labels labels= labelsService.selectByPrimaryKey(id);
            return R.ok().data("labels",labels);
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }
}
